﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SQLite;

public partial class SaleInfo_UnitMonth : UDCPage
{
    private int _did = -1;
    protected int DID
    {
        get { return _did; }
        set { _did = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DID = String.IsNullOrEmpty(Request.QueryString["Did"])
                ? GetDid() : Int32.Parse(Request.QueryString["Did"].ToString());
            SaleDataBind();
            G2SaleDataBind();
			G3SaleDataBind();
			WIFISaleDataBind();
            KDSaleDataBind();
            GHSaleDataBind();
        }
    }

    private void SaleDataBind()
    {
        string sqlstr = @"select sid,ServiceId,case isnew when 1 then '新用户' else '老用户' end as isnew
                    ,case iscontract when 1 then '预存话费送手机' else '购机入网送话费' end as iscontract,saledesc
                    ,strftime('%m-%d',saledate) as saledate,t3.dvname from ud_saleinfo_t t1 
                    inner join ud_developer_t t3 on t1.DvId = t3.DvId and t3.Did = :Did and t3.ifvalid = 1
                    where date(saledate) between date('now','start of month','localtime')
                                             and date('now','start of month','+1 month','-1 day','localtime') 
                    order by saledate,t1.dvid";
        SQLiteParameter[] spc = { 
                                    new SQLiteParameter(":Did",DbType.Int32)
                                };
        spc[0].Value = DID;
        DataSet ds = SQLiteHelper.ExecuteDataset(sqlstr, spc);
        UnitMonthSales.DataSource = ds;
        UnitMonthSales.DataBind();
        LRentCount.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }

    private void G2SaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.Get2GByDearID(GetDFname(), System.DateTime.Now.ToString("yyyyMM"));
        G2Sales.DataSource = ds;
        G2Sales.DataBind();
        G2Count.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }
	
	private void G3SaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.Get3GByDearID(GetDFname(), System.DateTime.Now.ToString("yyyyMM"));
        G3Sales.DataSource = ds;
        G3Sales.DataBind();
        G3Count.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }

	
	private void WIFISaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.GetWifiByDearID(GetDFname(), System.DateTime.Now.ToString("yyyyMM"));
        WIFISales.DataSource = ds;
        WIFISales.DataBind();
        NICCount.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }

    private void KDSaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();        
        DataSet ds = us.GetKDByDearID(GetDFname(), System.DateTime.Now.ToString("yyyyMM"));
        KDSales.DataSource = ds;
        KDSales.DataBind();
        KDCount.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }

    private void GHSaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.GetGHByDearID(GetDFname(), System.DateTime.Now.ToString("yyyyMM"));
        GHSales.DataSource = ds;
        GHSales.DataBind();
        GHCount.Text = "（" + ds.Tables[0].Rows.Count.ToString() + "）";
    }
}